using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Attributes;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Attributes.DomainAttributes;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Enums;
using System.Collections.Generic;
using System.ComponentModel;

namespace Baci.ArcGIS._SpatialStatisticsTools._ModelingSpatialRelationships
{
    /// <summary>
    /// <para>Exploratory Regression</para>
    /// <para>Evaluates all possible combinations of the input candidate explanatory variables, looking for OLS models that best explain the dependent variable within the context of user-specified criteria.</para>
    /// <para>评估输入候选解释变量的所有可能组合，寻找在用户指定条件的上下文中最好地解释因变量的 OLS 模型。</para>
    /// </summary>    
    [DisplayName("Exploratory Regression")]
    public class ExploratoryRegression : AbstractGPProcess
    {
        /// <summary>
        /// 无参构造
        /// </summary>
        public ExploratoryRegression()
        {

        }

        /// <summary>
        /// 有参构造
        /// </summary>
        /// <param name="_Input_Features">
        /// <para>Input Features</para>
        /// <para>The feature class or feature layer containing the dependent and candidate explanatory variables to analyze.</para>
        /// <para>包含要分析的因变量和候选解释变量的要素类或要素图层。</para>
        /// </param>
        /// <param name="_Dependent_Variable">
        /// <para>Dependent Variable</para>
        /// <para>The numeric field containing the observed values you want to model using OLS.</para>
        /// <para>包含要使用 OLS 建模的观测值的数值字段。</para>
        /// </param>
        /// <param name="_Candidate_Explanatory_Variables">
        /// <para>Candidate Explanatory Variables</para>
        /// <para>A list of fields to try as OLS model explanatory variables.</para>
        /// <para>要尝试作为 OLS 模型解释变量的字段列表。</para>
        /// </param>
        public ExploratoryRegression(object _Input_Features, object _Dependent_Variable, List<object> _Candidate_Explanatory_Variables)
        {
            this._Input_Features = _Input_Features;
            this._Dependent_Variable = _Dependent_Variable;
            this._Candidate_Explanatory_Variables = _Candidate_Explanatory_Variables;
        }
        public override string ToolboxName => "Spatial Statistics Tools";

        public override string ToolName => "Exploratory Regression";

        public override string CallName => "stats.ExploratoryRegression";

        public override List<string> AcceptEnvironments => ["scratchWorkspace", "workspace"];

        public override object[] ParameterInfo => [_Input_Features, _Dependent_Variable, _Candidate_Explanatory_Variables, _Weights_Matrix_File, _Output_Report_File, _Output_Results_Table, _Maximum_Number_of_Explanatory_Variables, _Minimum_Number_of_Explanatory_Variables, _Minimum_Acceptable_Adj_R_Squared, _Maximum_Coefficient_p_value_Cutoff, _Maximum_VIF_Value_Cutoff, _Minimum_Acceptable_Jarque_Bera_p_value, _Minimum_Acceptable_Spatial_Autocorrelation_p_value];

        /// <summary>
        /// <para>Input Features</para>
        /// <para>The feature class or feature layer containing the dependent and candidate explanatory variables to analyze.</para>
        /// <para>包含要分析的因变量和候选解释变量的要素类或要素图层。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Input Features")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public object _Input_Features { get; set; }


        /// <summary>
        /// <para>Dependent Variable</para>
        /// <para>The numeric field containing the observed values you want to model using OLS.</para>
        /// <para>包含要使用 OLS 建模的观测值的数值字段。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Dependent Variable")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public object _Dependent_Variable { get; set; }


        /// <summary>
        /// <para>Candidate Explanatory Variables</para>
        /// <para>A list of fields to try as OLS model explanatory variables.</para>
        /// <para>要尝试作为 OLS 模型解释变量的字段列表。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Candidate Explanatory Variables")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public List<object> _Candidate_Explanatory_Variables { get; set; }


        /// <summary>
        /// <para>Weights Matrix File</para>
        /// <para><xdoc>
        ///   <para>A file containing spatial weights that define the spatial relationships among your input features. This file is used to assess spatial autocorrelation among regression residuals. You can use the Generate Spatial Weights Matrix File tool to create this. When you do not provide a spatial weights matrix file, residuals are assessed for spatial autocorrelation based on each feature's 8 nearest neighbors.</para>
        ///   <para>Note: The spatial weights matrix file is only used to analyze spatial structure in model residuals; it is not used to build or to calibrate any of the OLS models.</para>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>包含空间权重的文件，用于定义输入要素之间的空间关系。此文件用于评估回归残差之间的空间自相关。您可以使用生成空间权重矩阵文件工具来创建此文件。如果未提供空间权重矩阵文件，则会根据每个要素的 8 个最近邻域评估残差的空间自相关。</para>
        ///   <para>注： 空间权重矩阵文件仅用于分析模型残差中的空间结构;它不用于构建或校准任何 OLS 模型。</para>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Weights Matrix File")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public object _Weights_Matrix_File { get; set; } = null;


        /// <summary>
        /// <para>Output Report File</para>
        /// <para>The report file contains tool results, including details about any models found that passed all the search criteria you entered. This output file also contains diagnostics to help you fix common regression problems in the case that you don't find any passing models.</para>
        /// <para>报告文件包含工具结果，包括找到的通过您输入的所有搜索条件的任何模型的详细信息。此输出文件还包含诊断程序，可帮助您在找不到任何传递模型的情况下修复常见的回归问题。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Output Report File")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public object _Output_Report_File { get; set; } = null;


        /// <summary>
        /// <para>Output Results Table</para>
        /// <para>The optional output table created containing the explanatory variables and diagnostics for all of the models within the Coefficient p-value and VIF value cutoffs.</para>
        /// <para>创建的可选输出表，其中包含系数 p 值和 VIF 值截止值内所有模型的解释变量和诊断。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Output Results Table")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public object _Output_Results_Table { get; set; } = null;


        /// <summary>
        /// <para>Maximum Number of Explanatory Variables</para>
        /// <para>All models with explanatory variables up to the value entered here will be assessed. If, for example, the Minimum Number of Explanatory Variables is 2 and the Maximum Number of Explanatory Variables is 3, the Exploratory Regression tool will try all models with every combination of two explanatory variables, and all models with every combination of three explanatory variables.</para>
        /// <para>将评估所有具有解释变量的模型，直到此处输入的值。例如，如果最小解释变量数为 2，最大解释变量数为 3，则探索性回归工具将尝试具有两个解释变量的每个组合的所有模型，以及具有三个解释变量的每个组合的所有模型。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Maximum Number of Explanatory Variables")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long _Maximum_Number_of_Explanatory_Variables { get; set; } = 5;


        /// <summary>
        /// <para>Minimum Number of Explanatory Variables</para>
        /// <para>This value represents the minimum number of explanatory variables for models evaluated. If, for example, the Minimum Number of Explanatory Variables is 2 and the Maximum Number of Explanatory Variables is 3, the Exploratory Regression tool will try all models with every combination of two explanatory variables, and all models with every combination of three explanatory variables.</para>
        /// <para>此值表示所评估模型的最小解释变量数。例如，如果最小解释变量数为 2，最大解释变量数为 3，则探索性回归工具将尝试具有两个解释变量的每个组合的所有模型，以及具有三个解释变量的每个组合的所有模型。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Minimum Number of Explanatory Variables")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long _Minimum_Number_of_Explanatory_Variables { get; set; } = 1;


        /// <summary>
        /// <para>Minimum Acceptable Adj R Squared</para>
        /// <para>This is the lowest Adjusted R-Squared value you consider a passing model. If a model passes all of your other search criteria, but has an Adjusted R-Squared value smaller than the value entered here, it will not show up as a Passing Model in the Output Report File. Valid values for this parameter range from 0.0 to 1.0. The default value is 0.05, indicating that passing models will explain at least 50 percent of the variation in the dependent variable.</para>
        /// <para>这是您认为通过模型的最低调整 R 平方值。如果模型通过了所有其他搜索条件，但调整后的 R 平方值小于此处输入的值，则它不会在输出报告文件中显示为通过模型。此参数的有效值范围为 0.0 到 1.0。默认值为 0.05，表示传递模型将解释因变量中至少 50% 的变异。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Minimum Acceptable Adj R Squared")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public double _Minimum_Acceptable_Adj_R_Squared { get; set; } = 0.5;


        /// <summary>
        /// <para>Maximum Coefficient p value Cutoff</para>
        /// <para>For each model evaluated, OLS computes explanatory variable coefficient p-values. The cutoff p-value you enter here represents the confidence level you require for all coefficients in the model in order to consider the model passing. Small p-values reflect a stronger confidence level. Valid values for this parameter range from 1.0 down to 0.0, but will most likely be 0.1, 0.05, 0.01, 0.001, and so on. The default value is 0.05, indicating passing models will only contain explanatory variables whose coefficients are statistically at the 95 percent confidence level (p-values smaller than 0.05). To relax this default you would enter a larger p-value cutoff, such as 0.1. If you are getting lots of passing models, you will likely want to make this search criteria more stringent by decreasing the default p-value cutoff from 0.05 to 0.01 or smaller.</para>
        /// <para>对于评估的每个模型，OLS 都会计算解释变量系数 p 值。此处输入的临界值 p 值表示模型中所有系数所需的置信水平，以便考虑模型通过。较小的 p 值表示较强的置信水平。此参数的有效值范围从 1.0 到 0.0，但很可能是 0.1、0.05、0.01、0.001 等。默认值为 0.05，表示传递的模型将仅包含其系数在统计上处于 95% 置信水平（p 值小于 0.05）的解释变量。要放宽此默认值，您将输入更大的 p 值截止值，例如 0.1。如果您获得大量通过的模型，您可能希望通过将默认 p 值截止值从 0.05 降低到 0.01 或更小来使此搜索条件更加严格。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Maximum Coefficient p value Cutoff")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public double _Maximum_Coefficient_p_value_Cutoff { get; set; } = 0.05;


        /// <summary>
        /// <para>Maximum VIF Value Cutoff</para>
        /// <para>This value reflects how much redundancy (multicollinearity) among model explanatory variables you will tolerate. When the VIF (Variance Inflation Factor) value is higher than about 7.5, multicollinearity can make a model unstable; consequently, 7.5 is the default value here. If you want your passing models to have less redundancy, you would enter a smaller value, such as 5.0, for this parameter.</para>
        /// <para>此值反映了您将容忍的模型解释变量之间的冗余（多重共线性）程度。当VIF（方差膨胀因子）值高于约7.5时，多重共线性会使模型不稳定;因此，7.5 是此处的默认值。如果希望传递模型具有较少的冗余，则应为此参数输入较小的值，例如 5.0。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Maximum VIF Value Cutoff")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public double _Maximum_VIF_Value_Cutoff { get; set; } = 7.5;


        /// <summary>
        /// <para>Minimum Acceptable Jarque Bera p value</para>
        /// <para>The p-value returned by the Jarque-Bera diagnostic test indicates whether the model residuals are normally distributed. If the p-value is statistically significant (small), the model residuals are not normal and the model is biased. Passing models should have large Jarque-Bera p-values. The default minimum acceptable p-value is 0.1. Only models returning p-values larger than this minimum will be considered passing. If you are having trouble finding unbiased passing models, and decide to relax this criterion, you might enter a smaller minimum p-value such as 0.05.</para>
        /// <para>Jarque-Bera 诊断检验返回的 p 值指示模型残差是否呈正态分布。如果 p 值具有统计显著性（较小），则模型残差不正态，并且模型存在偏差。通过的模型应具有较大的 Jarque-Bera p 值。默认的最小可接受 p 值为 0.1。只有返回大于此最小值的 p 值的模型才会被视为通过。如果您在查找无偏传递模型时遇到困难，并决定放宽此标准，则可以输入较小的最小 p 值，例如 0.05。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Minimum Acceptable Jarque Bera p value")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public double _Minimum_Acceptable_Jarque_Bera_p_value { get; set; } = 0.1;


        /// <summary>
        /// <para>Minimum Acceptable Spatial Autocorrelation p value</para>
        /// <para>For models that pass all of the other search criteria, the Exploratory Regression tool will check model residuals for spatial clustering using Global Moran's I. When the p-value for this diagnostic test is statistically significant (small), it indicates the model is very likely missing key explanatory variables (it isn't telling the whole story). Unfortunately, if you have spatial autocorrelation in your regression residuals, your model is misspecified, so you cannot trust your results. Passing models should have large p-values for this diagnostic test. The default minimum p-value is 0.1. Only models returning p-values larger than this minimum will be considered passing. If you are having trouble finding properly specified models because of this diagnostic test, and decide to relax this search criteria, you might enter a smaller minimum such as 0.05.</para>
        /// <para>对于通过所有其他搜索条件的模型，探索性回归工具将使用全局 Moran's I 检查空间聚类的模型残差。当此诊断测试的 p 值具有统计学意义（较小）时，它表明模型很可能缺少关键的解释变量（它不能说明全部情况）。遗憾的是，如果回归残差中存在空间自相关，则模型的指定错误，因此无法信任结果。对于此诊断测试，通过的模型应具有较大的 p 值。默认最小 p 值为 0.1。只有返回大于此最小值的 p 值的模型才会被视为通过。如果由于此诊断测试而无法找到正确指定的模型，并决定放宽此搜索条件，则可以输入较小的最小值，例如 0.05。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Minimum Acceptable Spatial Autocorrelation p value")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public double _Minimum_Acceptable_Spatial_Autocorrelation_p_value { get; set; } = 0.1;


        public ExploratoryRegression SetEnv(object scratchWorkspace = null, object workspace = null)
        {
            base.SetEnv(scratchWorkspace: scratchWorkspace, workspace: workspace);
            return this;
        }

    }

}